//封装请求
import { ElMessage as Message } from 'element-plus'
import axios from "axios";
//1. 创建一个request   3. 请求响应处理-response拦截器
const request = axios.create({
    baseURL:'',
    timeout: 1000*2,
    headers: {
        'Content-Type': 'application/json;charset=UFT-8',
    }
})


//2. 发送请求处理-request拦截器 
request.interceptors.request.use(
    config=>{
        return config;
    },error=>{
        return Promise.reject(error);
    }
)


//3. 响应拦截器
request.interceptors.response.use(
    res=>{
        const {success,code,message,data} = res.data;
        if(success) {
            return data;
        }
        Message.error(message)
    },error=>{
        console.log('err',error);
        return Promise.reject(error);
    }
)


export default request